package edu.gdkm.demo8;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class FileDemo4 {
    //读取花名册并生成数组储存每位同学的姓名
    public static void main(String[] args) throws IOException {
        File file = new File("./facebook.txt");
        FileReader fr = new FileReader(file);
        //使用缓存流实现文件的逐行读取
        BufferedReader br=new BufferedReader(fr);
        String name;

        int count=0;
        while((name =br.readLine())!=null){
            count++;
        }
        String students[] = new String[count];
        count=0;
        //缓存流的逐行读取会将读取指针下移，如果需要从头开始重新读取文件，需要重建缓存流
        br=new BufferedReader(new FileReader(file));
        while((name =br.readLine())!=null){
            students[count++]=name;
        }
//        for(int i=0;i<students.length;i++){
//            System.out.println(students[i]);
//        }
        for(String student:students){
            System.out.println(student);
        }

    }

}
